package com.tanhua.server.controller;

import com.tanhua.server.service.BaiduService;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * [位置] 模块
 */
@RestController
@RequestMapping("baidu")
public class BaiduController {

    @Autowired
    private BaiduService baiduService;

    /**
     * 更新位置
     */
    @PostMapping("location")
    public ResponseEntity<Void> updateLocation(@RequestBody Map<String, Object> param) {
        //APP上传的固定值：4.9E-324
        Double longitude = Double.valueOf(param.get("longitude").toString());
        //APP上传的固定值：4.9E-324
        Double latitude = Double.valueOf(param.get("latitude").toString());
        //APP上传的值：null
        String address = (String) param.get("addrStr");

        //因为APP端上传的数据问题，这里采用随机模拟位置数据
        longitude = RandomUtils.nextDouble(50D, 80D);//经度
        latitude = RandomUtils.nextDouble(50D, 80D);//纬度
        address = "武汉传智播客";

        this.baiduService.updateLocation(longitude, latitude, address);
        return ResponseEntity.ok(null);
    }
}